﻿using System;

namespace GameLogger
{
    /// <summary>
    /// 日志记录器(unity实现)
    /// </summary>
    class LoggerUnity : LoggerInner, ILogger
    {
        System.Action<System.Object> acOutputDebug;
        System.Action<System.Object> acOutputInfo;
        System.Action<System.Object> acOutputWarning;
        System.Action<System.Object> acOutputError;
        System.Action<System.Exception> acOutputException;

        /// <summary>
        /// Logger的Unity实现
        /// </summary>
        /// <param name="moduleName"></param>
        /// <param name="enableDebug"></param>
        /// <param name="enableInfo"></param>
        /// <param name="outputModuleName"></param>
        /// <param name="outputTime"></param>
        /// <param name="acOutputDebug"></param>
        /// <param name="acOutputInfo"></param>
        /// <param name="acOutputWarning"></param>
        /// <param name="acOutputError"></param>
        /// <param name="acOutputException"></param>
        public LoggerUnity(string moduleName, bool enableDebug, bool enableInfo, bool outputModuleName, bool outputTime,
            System.Action<System.Object> acOutputDebug,
            System.Action<System.Object> acOutputInfo,
            System.Action<System.Object> acOutputWarning,
            System.Action<System.Object> acOutputError,
            System.Action<System.Exception> acOutputException)
            : base(moduleName, enableDebug, enableInfo, outputModuleName, outputTime)
        {
            this.acOutputDebug = acOutputDebug;
            this.acOutputInfo = acOutputInfo;
            this.acOutputWarning = acOutputWarning;
            this.acOutputError = acOutputError;
            this.acOutputException = acOutputException;
        }

        /// <summary>
        /// 设置是否开启debug等级日志
        /// </summary>
        /// <param name="on"></param>
        public void EnableDebug(bool on)
        {
            mEnableDebug = on;
        }

        /// <summary>
        /// 设置是否开启info等级日志
        /// </summary>
        /// <param name="on"></param>
        public void EnableInfo(bool on)
        {
            mEnableInfo = on;
        }

        /// <summary>
        /// 记录debug等级日志
        /// </summary>
        /// <param name="message"></param>
        public void Debug(object message)
        {
            if (mEnableDebug)
            {
                acOutputDebug(Format(message));
            }
        }

        /// <summary>
        /// 记录infomation等级日志
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public void Debug(string format, params object[] args)
        {
            if (mEnableDebug)
            {
                acOutputDebug(Format(format, args));
            }
        }

        /// <summary>
        /// 记录infomation等级日志
        /// </summary>
        /// <param name="message"></param>
        public void Info(object message)
        {
            if (mEnableInfo)
            {
                acOutputInfo(Format(message));
            }
        }

        /// <summary>
        /// 记录warning等级日志
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public void Info(string format, params object[] args)
        {
            if (mEnableInfo)
            {
                acOutputInfo(Format(format, args));
            }
        }

        /// <summary>
        /// 记录warning等级日志
        /// </summary>
        /// <param name="message"></param>
        public void Warn(object message)
        {
            acOutputWarning(Format(message));
        }

        /// <summary>
        /// 记录debug等级日志
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public void Warn(string format, params object[] args)
        {
            acOutputWarning(Format(format, args));
        }

        /// <summary>
        /// 记录error等级日志
        /// </summary>
        /// <param name="message"></param>
        public void Error(object message)
        {
            acOutputError(Format(message));
        }

        /// <summary>
        /// 记录error等级日志
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public void Error(string format, params object[] args)
        {
            acOutputError(Format(format, args));
        }

        /// <summary>
        /// 记录exception
        /// </summary>
        /// <param name="exception"></param>
        public void Exception(Exception exception)
        {
            acOutputException(exception);
        }
    }
}
